package com.sheng.project.study.cglib;

import org.springframework.cglib.core.DefaultNamingPolicy;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.NoOp;

/**
 * @author liusheng
 * @date 2023/06/30
 */
public class NamingPolicyTest {

    public static void main(String[] args) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(NamingPolicyTest.class);
        enhancer.setCallback(NoOp.INSTANCE);
        // 接口 NamingPolicy 表示生成代理类的名字的策略，通过 Enhancer.setNamingPolicy 方法设置命名策略
        // 被代理 class name + "$$" + 使用 cglib 处理的 class name + "ByCGLIB" + "$$" + key 的 hashcode
        enhancer.setNamingPolicy(new DefaultNamingPolicy() {
            @Override
            protected String getTag() {
                return "-test-";
            }
        });
        Object proxy = enhancer.create();
        System.out.println(proxy.getClass());
    }
}
